﻿// *********************************************************************
// [DCOM Productions]
// [Copyright (C) DCOM Productions All rights reserved.]
// *********************************************************************

namespace BitFlex.Windows.Forms.Design {
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel.Design;
using System.Windows.Forms;

    /// <summary>
    /// Editor for <see cref="BitFlex.Windows.Forms.WizardPageCollection"/>
    /// </summary>
    public class WizardPageCollectionEditor : CollectionEditor {
        /// <summary>
        /// Initializes a new instance of the BitFlex.Windows.Forms.Design.WizardPageCollectionEditor class
        /// </summary>
        public WizardPageCollectionEditor()
            : base(typeof(WizardPageCollection<WizardPage>)) {
            // Todo: Any default constructor code here
        }

        protected override object SetItems(object editValue, object[] value) {
            Wizard wizard = Context.Instance as Wizard;
            if (wizard != null) {
                foreach (WizardPage item in value) { // Add any pages that were added
                    if (!wizard.Controls.Contains(item)) {
                        wizard.Controls.Add(item);
                        item.Dock = DockStyle.Fill;
                        item.Visible = false;
                    }
                }
                foreach (Control control in wizard.Controls) { // Remove any pages that were removed
                    WizardPage page = control as WizardPage;
                    if (page != null) {
                        if (!value.Contains(page)) {
                            wizard.Controls.Remove(control);
                        }
                    }
                }
            }
            return base.SetItems(editValue, value);
        }
    }
}